/**
 * 
 */
package com.xxx.action;

import java.lang.annotation.Inherited;
import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.gtgrid.model.GtPageInfo;
import org.apache.struts2.json.annotations.JSON;

import test.xxx.domain.model.TestUser;

import com.google.inject.Inject;

/**
 * 
 * 
 * @author Stevie
 * @since 2009-11-26
 * @version 1.0
 * 
 */
public class Workbench extends GtGridBaseAction<TestUser> {
	private String message;

	@Inject
	private TestUser u;
	List<TestUser> list = null;

	public String getMessage() {
		return message;
	}

	@JSON(name = "data")
	public List<TestUser> getPageData() {
		return pageData;
	}

	@JSON(name = "pageInfo")
	public GtPageInfo getPageInfo() {
		return pageInfo;
	}

	@Action(value = "/workbench/load", results = { @Result(type = "json") })
	public String load() {
		// this.setPageData(u.findAll());
		if (pageInfo.getTotalRowNum() < 0) {
			pageInfo.setTotalRowNum(u.countAll());
		}
		this.setPageData(u.findPageList(pageInfo.getStartRowNum()-1, pageInfo
				.getPageSize()));
		// }

		return SUCCESS;
	}

	@Action(value = "/workbench/save", results = { @Result(name = "save", type = "json") })
	public String save() {
		System.out.println("inserted Records:" + insertedRecords);
		u.save(insertedRecords);

		System.out.println("deleted Records:" + deletedRecords);
		u.remove(deletedRecords);
		// for(TestUser t : deletedRecords) {
		// u.remove(t.getId());
		// }

		return "save";
	}
}
